<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * 默认返回格式
     * @return mixed
     */
    public function result()
    {
        $result['errorCode'] = config('result.defaultCode');
        $result['errorMsg']  = config('result.defaultMsg');

        return $result;
    }

    /**
     * 获取请求参数
     * @param Request $request
     * @return array|mixed
     */
    public function getRequest(Request $request)
    {
        $method = strtoupper($request->method());
        $result = array();
        switch ($method)
        {
            case 'GET':
                $result = $request->all();
                break;
            case 'DELETE':
                $result = $request->all();
                break;
            case 'POST':
                $result = json_decode($request->getContent(), true);
                break;
            case 'PUT':
                $result = json_decode($request->getContent(), true);
                break;
            default:
                break;
        }

        return $result;
    }
}
